#if !defined(SCENEGRAPH_H)
#define SCENEGRAPH_H

#include "node.h"
#include <hash_map>
#include <string>

struct ID3DXEffectPool;
struct IDirect3DDevice9;
struct IDirect3DVertexBuffer9;
struct IDirect3DVertexDeclaration9;
struct ID3DXFont;
struct ID3DXSprite;

namespace gunsmith
{
class CResourceRenderTarget;
class CResourceManager;
class CResourceEffect;
class CResourceActiveTechnique;
class CResourceEffectVariables;

typedef stdext::hash_multimap<ENODETYPE, CNode*> NODETYPEMAP;
typedef stdext::hash_multimap<std::string, CResourceRenderTarget*> EFFECTMAP;

/*! \class CSceneGraph
	\brief Scene graph manages and handles the scene and nodes attached. */
class CSceneGraph
{
friend class CNode;

public:
			CSceneGraph		(CNode* pRootNode);
			~CSceneGraph	();
	void	Begin			();
	void	DestroyTree		();
	void	Draw			();
	void	DrawCombined	(CResourceEffect *pResEffect);
	void	DrawTo			(std::string sTechnique, CResourceRenderTarget *pResRenderTarget);
	CNode*	GetRoot			()																	const;
	void	Update			(float fDelta);
	void	SetDebug		(bool bDebugMode);
	void	SetRoot			(CNode *pNode);

private:
	void	AddNodesToHashMap	(CNode *pNodeBase);
	void	CreateFonts			();
	void	CreateScreenQuad	();
	void	DrawOnScreenText	(const char* cpText);
	void	DrawScreenQuad		();
	void	DrawTraverse		(CNode *pNodeBase);
	void	PopulateHashMap		();
	void	OutputFramesPerSec	(float fDelta);
	void	UpdateTraverse		(CNode *pNodeBase, float fDelta);

	bool						m_bDebugMode;
	bool						m_bNeedToUpdate;
	CNode*						m_pNodeRoot;
	NODETYPEMAP					m_mSceneObjects;
	IDirect3DDevice9			*m_pDevice;
	CResourceManager			*m_pResMngr;
	EFFECTMAP					m_mEffects;
	CResourceRenderTarget		*m_pRenderTargetDisplay;
	IDirect3DVertexBuffer9		*m_pVertexBuffer;
	IDirect3DVertexDeclaration9	*m_pVertexDecl;
	CResourceActiveTechnique	*m_pResActiveTechnique;
	CResourceEffectVariables	*m_pResEVars;
	ID3DXFont					*m_pFont;
	ID3DXSprite					*m_pSprite;
	float						m_fLastDelta;
};
};

#endif  //SCENEGRAPH_H
